package com.kuang.method;

import java.util.Scanner;

/**
 * @author wuJiaWei
 * @version 1.0
 * @date 2024/8/9
 * @time 15:02:23
 */
public class JiSuanQi {
    public static void main(String[] args) {
        JiSuanQi jsq = new JiSuanQi();
        jsq.compute();
    }
    public void compute(){
        System.out.println("欢迎使用计算器");
        System.out.println("-------------------------");
        Scanner scanner = new Scanner(System.in);

        double a = 0.0;
        double b = 0.0;
        double c = 0.0;
        String op;
        String command = "y";

        while (command.equals("y")){
            System.out.println("请输入第一个数字");
            a = scanner.nextDouble();
            System.out.println("请输入运算符 +-*/");
            op = scanner.next();
            System.out.println("请输入第二个数字");
            b = scanner.nextDouble();

            switch (op){
                case "+":
                    c = add(a,b);
                    break;
                case "-":
                    c = sub(a,b);
                    break;
                case "*":
                    c = mul(a,b);
                    break;
                case "/":
                    c = div(a,b);
                    break;
                default:
                    System.out.println("输入错误");
            }
            System.out.println("结果为" + c);
            System.out.println("是否继续计算？y/n");
            command = scanner.next();
        }
        System.out.println("谢谢使用");
        scanner.close();
    }
    /*****************************加减乘除方法****************************/
    public static double add(double a, double b){
        return a + b;
    }
    public static double sub(double a, double b){
        return a - b;
    }
    public static double mul(double a, double b){
        return a * b;
    }
    public static double div(double a, double b){
        return a * 1.0 / b;
    }
}
